import VuexPersistence from 'vuex-persist'

import { CacheEnum } from '@/enums/cacheEnum'

export const vuexLocal = new VuexPersistence({
  key: CacheEnum.vuexLocal,
  saveState: (key, state) => uni.setStorageSync(key, state),
  restoreState: (key) => uni.getStorageSync(key),
  modules: ['user', 'app']
})

export const vuexApp = new VuexPersistence({
  key: CacheEnum.vuexApp,
  saveState: (key, state) => uni.setStorageSync(key, state),
  restoreState: (key) => uni.getStorageSync(key),
  modules: ['oss', 'location', 'state']
})

export const hasCacheA = (name: string) =>
  !!uni.getStorageSync(CacheEnum.vuexLocal)?.[name]

export const hasCacheB = (name: string) =>
  !!uni.getStorageSync(CacheEnum.vuexApp)?.[name]
